module StaticHelper

  def draw_tree_from2(node)
    html = "<li>"
    html << "<a href='#'>#{node.name}</a>"

    if node.sub_unit.count != 0
      html << "<ul>"
    end

    node.sub_unit.each do |child_node|
      html << draw_tree_from2(child_node)
    end

    if node.sub_unit.count != 0
      html << "</ul>"
    end

    html << "</li>"
    html.html_safe
  end

  def draw_tree_from(node)
    html = "<ul><li>"
    html << "<a href='#'>#{node.name}</a>"
    node.sub_unit.each do |child_node|
      html << draw_tree_from(child_node)
    end
    html << "</li></ul>"
  end

  def display_segment(node)
    html = "<li>"
    node_class = node.sub_unit.count == 0 ? "file" : "folder"
    html << "<span class='#{node_class}'>#{h(node.name)}</span>"
    html << "<ul id='children_of_#{h(node.id)}'>"
    node.sub_unit.each do |child_node|
      html << display_segment(child_node)
    end
    html << "</ul></li>"
    html.html_safe
  end
end
